﻿using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using OS.Common.Core;

namespace OS.Orm.Interface
{
    /// <summary>
    /// 仓储层基类接口
    /// </summary>
    public interface IBaseRepository
    {
        /// <summary>
        /// 插入数据（默认Id自增长）
        /// </summary>
        /// <typeparam name="T">动态类型</typeparam>
        /// <param name="model">动态实体</param>
        /// <param name="isAuto">Id主键是否自增长</param>
        /// <returns></returns>
        Task<CustomResultId> Insert<T>(T model, bool isAuto = true);

        /// <summary>
        /// 全量更新
        /// </summary>
        /// <typeparam name="T">动态类型</typeparam>
        /// <param name="model">动态实体类</param>
        /// <param name="whereExpression">判断条件</param>
        /// <returns></returns>
        Task<CustomResult> UpdateAll<T>(T model, Expression<Func<T, bool>> whereExpression = null);

        /// <summary>
        /// 部分字段的更新
        /// </summary>
        /// <typeparam name="T">动态类型</typeparam>
        /// <param name="model">动态实体类</param>
        /// <param name="updateExpression">更新字段new{m.Name,....} Or new{m.Name="",....}</param>
        /// <param name="whereExpression">判断条件，如果为空默认根据Id判断</param>
        /// <returns></returns>
        Task<CustomResult> Update<T>(T model, Expression<Func<T, object>> updateExpression,
            Expression<Func<T, bool>> whereExpression = null);

        /// <summary>
        /// 软删除
        /// </summary>
        /// <typeparam name="T">动态类型</typeparam>
        /// <param name="model">动态实体</param>
        /// <param name="whereExpression">判断条件</param>
        /// <returns></returns>
        Task<CustomResult> DeleteSoft<T>(T model = null,
            Expression<Func<T, bool>> whereExpression = null) where T : BaseModel;

        /// <summary>
        /// 获取单个实体对象
        /// </summary>
        /// <typeparam name="T">动态类型</typeparam>
        /// <param name="model">动态实体类</param>
        /// <param name="whereExpression">判断条件</param>
        /// <returns></returns>
        Task<CustomResult<T>> Get<T>(T model = null, Expression<Func<T, bool>> whereExpression = null)
            where T : class;
    }
}